#ifndef __SCU_SCUSTAT_H
#define __SCU_SCUSTAT_H

#include <scos.h>
#include "sculist.h"

#ifdef __cplusplus
extern "C" {
#endif

#define SCU_STAT_MAXLINEWIDTH 5

typedef struct scus_proc_s
{
  int uid, id;
  char *name;

  scu_list_t bufs;
  scu_list_t ops;
} scus_proc_t;

typedef struct scus_stream_s
{
  int uid, id;
  unsigned long bytes;

  scu_list_t bufs;

  int open;
} scus_stream_t;

typedef struct scus_buf_s
{
  int uid, id, size;
  int counter;

  scus_stream_t *stream;
  scus_proc_t *proc;

  int open;
} scus_buf_t;

typedef struct scus_op_s
{
  int uid, id;
  int type;
  int line;
  char *text;
  scos_thread_t *thread;
  int threads;
  tmr_t timer;

  scu_list_t args;
  scus_proc_t *proc;

  int open;
} scus_op_t;

typedef struct scus_arg_s
{
  int uid, id;
  int intent;
  int type;
  /* TMCC doesn't understand anonymous unions */
  scus_buf_t *i;
  int d;
  double f;

  scus_op_t *op;
} scus_arg_t;

void scuStatInit(void);
scus_stream_t *scuStatAddStream(int id);
scus_buf_t *scuStatAddBuffer(int id, int size,
			     scus_stream_t *s, scus_proc_t *p);
scus_proc_t *scuStatAddProcessor(int id, char *name);
scus_op_t *scuStatAddOperation(int id, int type, int line, char *text,
			       scos_thread_t *thread, int threads, scus_proc_t *p);
scus_arg_t *scuStatOperationAddArgument(scus_op_t *o, int id, int type,
					int intent);
int scuStatStartOperation(scus_op_t *o);
int scuStatDefineArgument(scus_arg_t *a, ...);
int scuStatCloseStream(scus_stream_t *s);
int scuStatCloseBuffer(scus_buf_t *b, int counter, unsigned long bytes);
int scuStatCloseOperation(scus_op_t *o);
scus_stream_t *scuStatFindStream(int id);
scus_buf_t *scuStatFindBuffer(int id);
scus_proc_t *scuStatFindProcessor(int id);
scus_op_t *scuStatFindOperation(int id);
scus_arg_t *scuStatOperationFindArgument(scus_op_t *o, int id);
void scuStatWriteStructure(char *name, int pure);
void scuStatWriteSchedule(char *name);
void scuStatWrite(char *name);
void scuStatRead(char *file);

#ifdef __cplusplus
}
#endif

#endif /* __SCU_SCUSTAT_H */
